package cn.outsourcing.supermarket.controller.backstage;

import cn.outsourcing.supermarket.common.Result;
import cn.outsourcing.supermarket.common.constants.BackstageCategoryConstants;
import cn.outsourcing.supermarket.common.utils.ResultUtils;
import cn.outsourcing.supermarket.dto.OnlyIdPayloadDTO;
import cn.outsourcing.supermarket.dto.backstage.BackstageCategoryStatusDTO;
import cn.outsourcing.supermarket.dto.backstage.BackstageCategoryStoreDTO;
import cn.outsourcing.supermarket.dto.backstage.BackstageUpdateSortDTO;
import cn.outsourcing.supermarket.service.BackstageCategoryService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 后台分类控制器
 *
 * @author gzkemays
 * @since 2021/11/4 15:06
 */
@RestController
@RequestMapping("/admin/category")
public class CategoryController {
  @Resource BackstageCategoryService backstageCategoryService;

  @PostMapping("/store")
  public Result store(@RequestBody BackstageCategoryStoreDTO dto) {
    return ResultUtils.simpleResult(backstageCategoryService.store(dto));
  }

  @GetMapping("/info")
  public Result info(OnlyIdPayloadDTO dto) {
    return ResultUtils.simpleResult(backstageCategoryService.info(dto));
  }

  @GetMapping("/channelStatus")
  public Result channelStatus(BackstageCategoryStatusDTO dto) {
    return ResultUtils.simpleResult(
        backstageCategoryService.updateStatus(dto, BackstageCategoryConstants.STATUS_CHANNEL));
  }

  @GetMapping("/categoryStatus")
  public Result categoryStatus(BackstageCategoryStatusDTO dto) {
    return ResultUtils.simpleResult(
        backstageCategoryService.updateStatus(dto, BackstageCategoryConstants.STATUS_CATEGORY));
  }

  @GetMapping("/showStatus")
  public Result showStatus(BackstageCategoryStatusDTO dto) {
    return ResultUtils.simpleResult(
        backstageCategoryService.updateStatus(dto, BackstageCategoryConstants.STATUS_SHOW));
  }

  @PostMapping("/updateSort")
  public Result updateSort(@RequestBody BackstageUpdateSortDTO dto) {
    return ResultUtils.simpleResult(backstageCategoryService.updateSort(dto));
  }

  @PostMapping("/destory")
  public Result destroy(@RequestBody OnlyIdPayloadDTO dto) {
    return ResultUtils.simpleResult(backstageCategoryService.destroy(dto));
  }
}
